/**
 * 
 */
package com.et114.modules.org.cells;

import java.util.Collection;

//import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.cell.Cell;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.util.HtmlBuilder;

//import com.et114.components.acegi.Constants;
//import com.et114.components.acegi.Constants;
import com.et114.modules.org.vo.RoleVo;

/**
 * @author guanhw
 *
 */
public class RoleIdMultipleSelectedCell implements Cell {
	/*
	public String getDataColName ( ) {
		// TODO Auto-generated method stub
		return "roleId";
	}
	
	
	public String getShowColName ( ) {
		// TODO Auto-generated method stub
		return "deleteId";
	}
	*/
	
	protected  Log logger = LogFactory.getLog( this.getClass ( ) );
	public final static String	SELECTED_PRESIDENTS	= "SELECTED_PRESIDENTS";
	public final static String	SELECTED			= "SELECTED";
	public final static String	UNSELECTED			= "UNSELECTED";

	public String getExportDisplay ( TableModel model , Column column ) {
		return null;
	}

	public String getHtmlDisplay ( TableModel model , Column column ) {
		HtmlBuilder html = new HtmlBuilder();
		html.td ( 0 ).xclose ( ) ;
		int count = 0 ; 
		try {
			RoleVo bean = ( RoleVo )model.getCurrentRowBean();
			
			Long roleId = bean.getRoleId ( );
			//check acl 
			long ct = System.currentTimeMillis ( ) ;
			count = bean.getCountRel ( ) .intValue ( )  ; 
			logger.debug ( "role check time .." + ( System.currentTimeMillis ( ) - ct ) ) ; 
			String scn = "deleteId";
			Collection selectedPresidentsIds = ( Collection ) model.getContext().getSessionAttribute( SELECTED_PRESIDENTS );
			if ( selectedPresidentsIds != null	&& selectedPresidentsIds.contains( roleId.toString ( ) ) ) {
				html.input( "checkbox" ).name( scn ).value( roleId.toString ( ) );
				html.checked();
				html.xclose();									
			} else {
				html.input( "checkbox" ).name( scn ).value(	roleId.toString ( ) );	
				if ( count > 0  ) html.disabled ( );								
				html.xclose();
			}
		} catch ( Exception e ) {
			logger.error (  e.getMessage ( ) , e ) ;
		}
		html.tdEnd ( );
		return html.toString();
	}	
	
}
